package com.ambientrs.script.methods;

import java.util.Random;

public class Calculations {

    private static final Random rand = new Random();

    /**
     * Generates a random integer between min and max (both inclusive).
     *
     * @param min The minimum possible number.
     * @param max The maximum possible number.
     * @return The random number.
     */
    public static int boundedRandom(int min, int max) {
        return rand.nextInt(Math.abs(max - min) + 1) + (max < min ? max : min);
    }

    /**
     * Generates a random number a maximum of the specified distance from the
     * base.
     *
     * @param base    The number to randomize.
     * @param variant The maximum distance from the base.
     * @return The randomized base.
     */
    public static int random(int base, int variant) {
        if (variant < 0)
            throw new IllegalArgumentException("variant must be positive");
        return rand.nextInt(variant * 2 + 1) - variant + base;
    }

}
